package com.tg.app.activity;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.tg.app.R;
import com.tange.base.toolkit.PreferenceUtil;



public class VideoAutoPlayActivity extends AppCompatActivity implements View.OnClickListener {

    RelativeLayout gg_wifi;
    RelativeLayout wifi;
    RelativeLayout close;
    ImageView g4g_wifi;
    ImageView wifi_choose;
    ImageView close_choose;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//remove title bar  即隐藏标题栏
        setContentView(R.layout.activity_video_auto_play);
        getSupportActionBar().hide();// 隐藏ActionBar

        initView();
    }

    private void initView() {
        int autoPlayFlag = PreferenceUtil.getInt(this,"autoPlayFlag");
        setToolTitle();
        gg_wifi = findViewById(R.id.gg_wifi);
        wifi = findViewById(R.id.wifi);
        close = findViewById(R.id.close);
        gg_wifi.setOnClickListener(this);
        wifi.setOnClickListener(this);
        close.setOnClickListener(this);
        g4g_wifi = findViewById(R.id.g4g_wifi);
        wifi_choose = findViewById(R.id.wifi_choose);
        close_choose = findViewById(R.id.close_choose);
        setVisible(autoPlayFlag);
        findViewById(R.id.back_toolbar).setOnClickListener(this);
    }

    private void setToolTitle() {
        RelativeLayout toolbar = findViewById(R.id.toolbar);
        TextView title = toolbar.findViewById(R.id.device_name);
        title.setText(R.string.video_auto_play);
    }

    @Override

    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.gg_wifi) {
            setVisible(0);
        } else if (id == R.id.wifi) {
            setVisible(1);
        } else if (id == R.id.close) {
            setVisible(2);
        } else if (id == R.id.back_toolbar) {
            finish();
        }
    }

    private void setVisible(int n){
        PreferenceUtil.setInt(getBaseContext(),"autoPlayFlag",n);
        if(n == 0) {
            g4g_wifi.setVisibility(View.VISIBLE);
            wifi_choose.setVisibility(View.INVISIBLE);
            close_choose.setVisibility(View.INVISIBLE);
        }else if(n == 1){
            g4g_wifi.setVisibility(View.INVISIBLE);
            wifi_choose.setVisibility(View.VISIBLE);
            close_choose.setVisibility(View.INVISIBLE);
        }else if(n == 2){
            g4g_wifi.setVisibility(View.INVISIBLE);
            wifi_choose.setVisibility(View.INVISIBLE);
            close_choose.setVisibility(View.VISIBLE);
        }
    }

}
